package com.fenghongzhang.day005;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

public class MainActivity extends AppCompatActivity {
    private EditText edit;
    private Button send;
    private LinearLayout ll;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        edit = (EditText) findViewById(R.id.edit);
        send = (Button) findViewById(R.id.send);
        ll = (LinearLayout) findViewById(R.id.ll);


        FragmentManager supportFragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = supportFragmentManager.beginTransaction();
        ContentFragment contentFragment = new ContentFragment(); //1
        fragmentTransaction.add(R.id.ll,contentFragment);
        fragmentTransaction.commit();


        send.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String string = edit.getText().toString();

                FragmentManager supportFragmentManager = getSupportFragmentManager();
                FragmentTransaction fragmentTransaction = supportFragmentManager.beginTransaction();
                ContentFragment contentFragment1 = new ContentFragment();

                Bundle bundle = new Bundle();
                bundle.putString("name",string);
                contentFragment1.setArguments(bundle);

                //添加
                fragmentTransaction.replace(R.id.ll,contentFragment1);
                fragmentTransaction.commit();

            }
        });

    }
    class MyTask extends AsyncTask<String,Void,String>{

        @Override
        protected String doInBackground(String... strings) {
            return null;
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }
    }

    class MyTask1 extends AsyncTask<String,Integer,Bitmap>{

        //子线程
        @Override
        protected Bitmap doInBackground(String... strings) {
            publishProgress(200);
            return null;
        }

        //更新ui
        @Override
        protected void onPostExecute(Bitmap bitmap) {
            super.onPostExecute(bitmap);
        }

        //更新进度
        @Override
        protected void onProgressUpdate(Integer... values) {
            //100
            //200
            super.onProgressUpdate(values);
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }
    }

}
